package com.TrainingCenter.entity;

import javax.persistence.*;
import java.sql.Date;

/**
 * Created with IntelliJ IDEA.
 * User: ibook
 * Date: 30.04.14
 * Time: 11:29
 * To change this template use File | Settings | File Templates.
 */
@Table(name = "personal_data", schema = "public", catalog = "TrainingCenter")
@Entity
public class PersonalData implements Persitent {
    @OneToOne(cascade = CascadeType.ALL)
    @PrimaryKeyJoinColumn
    private User user;

    @Column(name = "id_user")
    @Id
    private int idUser;

    @Column(name = "firstname")
    @Basic
    private String firstname;

    @Column(name = "midltname")
    @Basic
    private String midltname;

    @Column(name = "lastname")
    @Basic
    private String lastname;

    @Column(name = "birthday")
    @Basic
    private Date birthday;

    @Column(name = "sex")
    @Enumerated(EnumType.STRING)
    @Basic
    private Sex sex;

    public enum Sex {
        male, female;
    }
    public int getId() {
        return idUser;
    }

    public void setId(int idUser) {
        this.idUser = idUser;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }


    public String getMidltname() {
        return midltname;
    }

    public void setMidltname(String midltname) {
        this.midltname = midltname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }


    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Sex getSex() {
        return sex;
    }

    public void setSex(Sex sex) {
        this.sex = sex;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PersonalData that = (PersonalData) o;

        if (idUser != that.idUser) return false;
        if (birthday != null ? !birthday.equals(that.birthday) : that.birthday != null) return false;
        if (firstname != null ? !firstname.equals(that.firstname) : that.firstname != null) return false;
        if (lastname != null ? !lastname.equals(that.lastname) : that.lastname != null) return false;
        if (midltname != null ? !midltname.equals(that.midltname) : that.midltname != null) return false;
        if (sex != null ? !sex.equals(that.sex) : that.sex != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = idUser;
        result = 31 * result + (firstname != null ? firstname.hashCode() : 0);
        result = 31 * result + (midltname != null ? midltname.hashCode() : 0);
        result = 31 * result + (lastname != null ? lastname.hashCode() : 0);
        result = 31 * result + (birthday != null ? birthday.hashCode() : 0);
        result = 31 * result + (sex != null ? sex.hashCode() : 0);
        return result;
    }
}
